import axios from 'axios'
import Vue from 'Vue'
import { baseUrl } from '../../config/base'

//axios.defaults.withCredentials=true;
Vue.prototype.$http = axios
export default {
    state: {
        status: ''
    },
    getters: {
        status: function (state) {
          return state.status
        }
    },
    mutations: {
        getStatus(state,data) {
            console.log(data)
            state.status = data
        }
    },
    actions: {
        //手机号验证
        checkPhone(context,params) {
          return new Promise(function(resolve,reject){
            axios.post(baseUrl + '/user/checkPhone', {params},{withCredentials : true})
              .then(res=> {
                if(res.body.code == '0'){
                  resolve(res.body)
                }
                reject({
                  code: res.body.code,
                  msg: res.body.msg
                })
              }).catch(err=> {
                console.log(err)
            })
          })
        },
        checkAccount(context,params) {
          return new Promise(function(resolve,reject){
            axios.post(baseUrl + '/user/checkAccount', {params},{withCredentials : true})
              .then(res=> {
                if(res.body.code == '0'){
                  resolve(res.body)
                }
                reject({
                  code: res.body.code,
                  msg: res.body.msg
                })
              }).catch(err=> {
              console.log(err)
            })
          })
        },
        findUser(context,params) {
          return new Promise(function(resolve,reject){
            axios.post(baseUrl + '/user/registerUser', {params},{withCredentials : true})
              .then(res=> {
                resolve(res)
              }).catch(err=> {
              console.log(err)
            })
          })
        }

    }
}
